import logging

import redis

pool = redis.ConnectionPool(host='185.227.152.91', password='hfhdtrDGKGIG', port=6377, db=1, decode_responses=True)
redis = redis.Redis(connection_pool=pool)


def get_now_price(symbol):
    return float(redis.get(symbol + "_now_price"))


def get_score(symbol):
    return int(redis.get(symbol + "_score"))


def get_asset_type(symbol):
    if symbol == "ETCUSDT":
        return "USDT"


def set_accuracy(symbol, num: float):
    if symbol == "ETCUSDT":
        var = str(num + 0.01).split(".")
        if len(var) > 0:
            return var[0] + "." + var[1][0:2]
        else:
            return var[0]


def logging_and_print(data):
    logging.info(data)
    print(data)


def get_logger(name):
    logger = logging.getLogger(name)
    filename = f'{name}.log'
    fh = logging.FileHandler(filename, mode='a+', encoding='utf-8')
    formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s')
    logger.setLevel(logging.INFO)
    fh.setFormatter(formatter)
    logger.addHandler(fh)
    return logger
